import { defHttp } from '/@/utils/http/axios'
import { RoleInfo, RoleFormModel, RolePermissionModel } from './model/roleModel'
import { getMenuListResultModel } from './model/menuModel'

import { BasicFetchResult, BasicFetchObjectResult } from '/@/api/model/baseModel'

enum Api {
  GetRoleList = '/role/list',
  AddRole = '/role/create',
  DeleteRole = '/role/delete',
  listPermission = '/role/list/permission',
  setPermission = '/role/permission',
}

/**
 * 获取角色列表
 *
 * @returns 返回角色列表请求的响应结果
 */
export function listRole() {
  return defHttp.get<RoleInfo[]>({ url: Api.GetRoleList }, { errorMessageMode: 'none' })
}

export function addRole(params: RoleFormModel) {
  return defHttp.post<Boolean>({ url: Api.AddRole, params }, { errorMessageMode: 'none' })
}

export function deleteRole(params: string) {
  return defHttp.delete<Boolean>(
    { url: Api.DeleteRole, params: { id: params } },
    { errorMessageMode: 'none' },
  )
}

export const listPermission = (params: string) => {
  return defHttp.get<string[]>({ url: Api.listPermission, params: { roleId: params } })
}

export function setPermission(data: RolePermissionModel) {
  return defHttp.post<Boolean>({ url: Api.setPermission, data })
}
